<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script>
description('This test aims to check for rangeUnderflow flag with a number input field');

var input = document.createElement('input');

function checkUnderflow(value, min, disabled)
{
    input.value = value;
    input.min = min;
    input.disabled = !!disabled;
    var underflow = input.validity.rangeUnderflow;
    var resultText = 'The value "' + input.value + '" ' +
        (underflow ? 'undeflows' : 'doesn\'t underflow') +
        ' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
    if (underflow)
        testPassed(resultText);
    else
        testFailed(resultText);
}

function checkNotUnderflow(value, min, disabled)
{
    input.value = value;
    input.min = min;
    input.disabled = !!disabled;
    var underflow = input.validity.rangeUnderflow;
    var resultText = 'The value "' + input.value + '" ' +
        (underflow ? 'underflows' : 'doesn\'t underflow') +
        ' the minimum value "' + input.min + '"' + (disabled ? ' when disabled.' : '.');
    if (underflow)
        testFailed(resultText);
    else
        testPassed(resultText);
}

debug('Type=number');
input.type = 'number';
input.max = '';
// No underflow cases
input.type = 'number';
checkNotUnderflow('101', '100');  // Very normal case.
checkNotUnderflow('-99', '-100');
checkNotUnderflow('101', '1E+2');
checkNotUnderflow('1.01', '1.00');
checkNotUnderflow('abc', '100');  // Invalid value.
checkNotUnderflow('', '1');  // No value.
checkNotUnderflow('-1', '');  // No min.
checkNotUnderflow('-1', 'xxx');  // Invalid min.
// The following case should be rangeUnderflow==true ideally.  But the "double" type doesn't have enough precision.
checkNotUnderflow('0.999999999999999999999999999999999999999998', '0.999999999999999999999999999999999999999999');

// Underflow cases
checkUnderflow('99', '100');
checkUnderflow('-101', '-100');
checkUnderflow('99', '1E+2');
input.max = '100';  // value < min && value > max
checkUnderflow('101', '200');
checkUnderflow('-.8', '1');

// Disabled
checkUnderflow('99', '1E+2', true);
</script>
</body>
</html>
